<?php

class SendEmail {

    function SendMail($name, $email, $base, $header, $subjects, $BodyHeader, $BodyMessage) {
        require_once('class.phpmailer.php');
        $mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
        $mail->IsSMTP(); // telling the class to use SMTP
        /* select from config setting */
        $get_config_sever = select(Tblrefcode::tblname, array(Tblrefcode::value), array(Tblrefcode::name => 'mail_server', Tblrefcode::type => 'global_setting'));
        $row_config_sever = mysql_fetch_assoc($get_config_sever);
        $get_config_port = select(Tblrefcode::tblname, array(Tblrefcode::value), array(Tblrefcode::name => 'mail_port', Tblrefcode::type => 'global_setting'));
        $row_config_port = mysql_fetch_assoc($get_config_port);
        $get_config_user = select(Tblrefcode::tblname, array(Tblrefcode::value), array(Tblrefcode::name => 'mail_user_login', Tblrefcode::type => 'global_setting'));
        $row_config_user = mysql_fetch_assoc($get_config_user);
        $get_config_password = select(Tblrefcode::tblname, array(Tblrefcode::value), array(Tblrefcode::name => 'mail_user_password', Tblrefcode::type => 'global_setting'));
        $row_config_password = mysql_fetch_assoc($get_config_password);
        /* end select from config setting */
        try {
            //$mail->Host       = "mail.yourdomain.com"; // SMTP server
            //$mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
			$admin_email = ((!empty($row_config_user)) ? $row_config_user[Tblrefcode::value] : '7727psarinternet@gmail.com');
            $mail->SMTPAuth = true;                  // enable SMTP authentication
            $mail->SMTPSecure = "SSL";                 // sets the prefix to the servier
            $mail->Host = ((!empty($row_config_sever)) ? $row_config_sever[Tblrefcode::value] : 'smtp.gmail.com');      // sets GMAIL as the SMTP server
            $mail->Port = ((!empty($row_config_port)) ? $row_config_port[Tblrefcode::value] : '587');                   // set the SMTP port for the GMAIL server
            $mail->Username = ((!empty($row_config_user)) ? $row_config_user[Tblrefcode::value] : '7727psarinternet@gmail.com');  // GMAIL username
            $mail->Password = ((!empty($row_config_password)) ? $row_config_password[Tblrefcode::value] : 'l1v2n3s4');            // GMAIL password
            $mail->SetFrom($admin_email, 'Psarinternet');
            $mail->AddAddress($email, 'Psarinternet');
            $mail->AddReplyTo($admin_email, 'Psarinternet');
            $mail->Subject = $subjects;
            $mail->IsHTML(true);
            //$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
            $bodymsn = '<html>
					<header>
					<title>' . $BodyHeader . '</title>
					</header>
					<body><div class="ii gt adP adO" id=":oz">
						<div id=":p0">
							<div
								style="border-radius: 5px; border: solid 1px #dfdfdf; font-family: Arial; word-wrap: break-word; width: 670px">
								<div class="adM"></div>
								<table cellspacing="0" cellpadding="0"
									style="background-color: #ededed; border-radius: 5px 5px 0 0; width: 670px">
									<tbody>
										<tr>
											<td>
												<div style="padding: 30px 30px 0; font-size: 20px">
													' . $BodyHeader . '
													<div
														style="margin-top: 20px; width: 0; min-height: 0; border-bottom: 10px solid #fff; border-left: 10px solid transparent; border-right: 10px solid transparent">
													</div>
												</div>
											</td>
											<td
												style="vertical-align: middle; text-align: right; padding-right: 30px">
												<img src="' . $base . '/images/logo1.png"/>
											</td>
										</tr>
									</tbody>
								</table>
								<div style="line-height: 18px; font-size: 14px">
									<div style="padding: 30px 30px 40px">
										' . $BodyMessage . '
									</div>
								</div>
								<div
									style="line-height: 18px; border-radius: 0 0 5px 5px; font-size: 14px; padding: 30px; border-top: solid 1px #dfdfdf">
									<p>
										<strong>Psarinternet</strong><br>
										<br>#2C, Street 120, Sangkat Phsar Thmey II, Khan Daun Penh, Phnom Penh, Cambodia.<br> Email:&nbsp;<a
											target="_blank" href="mailto:info@psarinternet.com">info@psarinternet.com</a><br>
										Tel : +855 70 772 799
									</p>
								</div>
							</div>
							<div class="yj6qo"></div>
							<div class="adL"></div>
						</div>
					</div>
					</body>
					</html>';
            $mail->MsgHTML($bodymsn);
            $mail->Send();
            return TRUE;
        } catch (Exception $e) {
            return FALSE;
        }
        // end to confirm email
    }

}

?>
